export function toTree(data, ids, pids) {
    // 平铺数组转为树形结构数组
    const id = ids;
    const pid = pids;
    const result = [];
    if (!Array.isArray(data)) {
      return result;
    }
    data.forEach(item => {
      delete item.children;
    });
    const map = {};
    data.forEach(item => {
      map[item[id]] = item;
    });
    data.forEach(item => {
      const parent = map[item[pid]];
      if (parent) {
        (parent.children || (parent.children = [])).push(item);
      } else {
        result.push(item);
      }
    });
    return result;
  }
  export default toTree;
  